/**
 * Candidate number: 35834
 */
package tv.starfu.sequencer.model;

import de.lessvoid.nifty.NiftyEventSubscriber;
import tv.starfu.sequencer.components.SequenceComponent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.TreeMap;
import net.beadsproject.beads.core.AudioContext;
import net.beadsproject.beads.core.Bead;
import net.beadsproject.beads.ugens.Clock;
import tv.starfu.sequencer.ActivationGrid;
import tv.starfu.sequencer.components.TimeVector;
import tv.starfu.sequencer.matrix.MatrixAtomPhaseChangedEvent;

/* Stores all Patterns and Sequences */
public class SequencerModel {
   
    // Pattern/Sequence stuff
    private HashMap<Integer, Track> activeTracks;
    private TreeMap<TimeVector, ArrayList<Event>> longCount;
    private TreeMap<String, ArrayList<Integer>> drumPattern;
    private TreeMap<String, SequenceComponent> sequencesByStyle;
    
    private int[][] niftyGrid;  
    
    
    public SequencerModel() {
    
        // Init drum grid
       niftyGrid = new int[16][8];
       
       // Fill drum grid
       for(int x = 0; x < 16; x++) {
           for (int y = 0; y < 8; y++) {
              niftyGrid[x][y] = 0;
            }
        }
        
    }
    
    public int getPhase(int channelPls, int stepPls) {
        return niftyGrid[channelPls][stepPls];
    }
    
    public void setEvent(int channel, int step, int phase) {
        niftyGrid[channel][step] = phase;
    }

  
  @NiftyEventSubscriber(pattern="mb.*")
  public void onClick(final String id, final MatrixAtomPhaseChangedEvent event) {
      int phase = event.getPhase();
      int channel = event.getChannel();
      int step = event.getStep();
      
      niftyGrid[channel][step] = phase;
  
  }


    public HashMap<Integer, Track> getActiveTracks() {
        return activeTracks;
    }

    public void setActiveTracks(HashMap<Integer, Track> activeTracks) {
        this.activeTracks = activeTracks;
    }

    public TreeMap<TimeVector, ArrayList<Event>> getLongCount() {
        return longCount;
    }

    public void setLongCount(TreeMap<TimeVector, ArrayList<Event>> longCount) {
        this.longCount = longCount;
    }

    public TreeMap<String, SequenceComponent> getSequencesByStyle() {
        return sequencesByStyle;
    }

    public void setSequencesByStyle(TreeMap<String, SequenceComponent> sequencesByStyle) {
        this.sequencesByStyle = sequencesByStyle;
    }
    
}
